# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Guillaume ALAUX <guillaume@archlinux.org>
# Contributor: Kristof JOZSA <kristof.jozsa@gmail.com>
# Contributor: Andrius Semionovas <aneworld at gmail dot com>

pkgname=visualvm
pkgver=2.1.6
_shortver=${pkgver//\./}
pkgrel=1
pkgdesc='Visual tool integrating several commandline JDK tools and lightweight profiling capabilities'
url='https://visualvm.github.io/'
arch=('x86_64')
license=('custom:GPL')
depends=('java-environment')
source=(https://github.com/visualvm/visualvm.src/releases/download/${pkgver}/${pkgname}_${_shortver}.zip
        visualvm.desktop
        icon.png)
sha256sums=('9b1c8adab1f776ea0ab2fca71be4f0e79f0ea6c6d0c9f170506851cccfdc1963'
            'e820807e8d78446cf156a3947d97856e24865bb0d8c957e9ce2fed309c737441'
            '452fbd85c968ec7176c5894bc4106b7e25310314d44278d807510675b6a5c864')
b2sums=('ff25371b38bf483756750fa9a068976277d92eb644a03bd56b7d59ecbdb013f95c27b348c8b2375ddb6aba12595273d6e1e736c8381a30c1772ddf803a2ce589'
        'ec51d5613e0b8103c5596b8549bfea2eb7cf6fe7792c790ef67007d469c3ddb0fb8990f9ea1aa575f412b62787c43225a583c2d6936393cbcb1938d396717e18'
        '5f7659620de6b3d67716e700a5e8724e03cf3343c188a2d5c2470950c27c8e045209e87951971a969497b38f0dd5eff8a021e427367b838254040c6d25eb0b5d')

package() {
  cd ${pkgname}_${_shortver}

  install -d "${pkgdir}/usr/share/${pkgname}"
  cp -R bin platform visualvm "${pkgdir}/usr/share/${pkgname}"

  install -d "${pkgdir}/etc/${pkgname}"
  cp -R etc/* "${pkgdir}/etc/${pkgname}"
  ln -s /etc/${pkgname} "${pkgdir}/usr/share/${pkgname}/etc"
  # 'visualvm' shell script cannot even set his own variable 'visualvm_jdkhome'
  sed -i \
    -e 's|#visualvm_jdkhome="/path/to/jdk"|visualvm_jdkhome="${JAVA_HOME}"|' \
    -e 's|visualvm_default_options="|visualvm_default_options="-J-Dawt.useSystemAAFontSettings=on |' \
      "${pkgdir}/etc/${pkgname}/visualvm.conf"

  find "${pkgdir}"/usr/share/${pkgname} \( -name "*.exe" -o -name "*.dll" \) -delete

  install -d "${pkgdir}/usr/bin"
  ln -s /usr/share/${pkgname}/bin/visualvm "${pkgdir}/usr/bin/${pkgname}"

  install -Dm 644 "${srcdir}/icon.png" -t "${pkgdir}/usr/share/${pkgname}"
  install -Dm 644 "${srcdir}/visualvm.desktop" -t "${pkgdir}/usr/share/applications"

  install -Dm 644 LICENSE.txt -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

# vim: ts=2 sw=2 et:
